<!--交易中心的汇款管理页面-->
<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">汇款管理</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>汇款管理</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="remittance-search-key">
                <option value="">-请选择-</option>
                <option value="companyName">公司名</option>
                <option value="username">录用的人</option>
                <option value="job">录用的岗位</option>
            </select>&emsp;
            <input id="remittance-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="remittance-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
            <button id="remittance-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>

        </div>

        <table class="layui-table" id="remittance-table" lay-filter="remittance-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<!--汇款管理没有修改-->
<!--   <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>-->
<script type="text/html" id="remittance-table-bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表格状态列 -->
<!--<script type="text/html" id="remittance-tpl-state">-->
<!--    <input type="checkbox" lay-filter="remittance-tpl-state" value="{{d.id}}" lay-skin="switch" lay-text="热招中|关闭"-->
<!--           {{d.conduct==0?'checked':''}}/>-->
<!--</script>-->

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;


        // 渲染表格
        table.render({
            elem: '#remittance-table',
            // url: config.base_server + 'user_query.json',
            url: config.base_server + 'api-trade/remittance/findAllRemittance',
            method: 'GET',
            where: {
                access_token: config.getToken().access_token
            },
            page: true,
            //todo
            // 数据结果展示
            cols: [[
                {field: 'id', sort: true, title: '汇款公司编号'},
                {field: 'companyname', sort: true, title: '汇款公司'},
                // {field: 'remark', sort: true, title: '录用岗位'},
                {field: 'userId', sort: true, title: '收款人编号'},
                {field: 'nickName', sort: true, title: '收款人员姓名'},
                {field: 'batchId',sort: true,title: '付款批次'},
                // {field: 'prePay',sort: true,title: '预期金额'},
                // {field: 'actuallyPay',sort: true,title: '实付金额'},
                {sort: true, title: '是否付款',templet:function (res) {
                        return res.payStatus===1?"已付款":"未支付"
                    }},
                {title: '操作',toolbar:"#remittance-table-bar"}
            ]]
        });
        // 添加按钮点击事件
        $('#remittance-btn-add').click(function () {
            showEditModel();
        });

        // 工具条点击事件
        table.on('tool(remittance-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
                showEditModel(data);
            } else if (layEvent === 'reset') { // 重置密码
                layer.confirm('确定重置此用户的密码吗？', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('api-user/users/'+obj.data.id+'/resetPassword', {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'POST');
                });
            } else if (layEvent ==='del'){
                doDelete(obj);//删除
            }
        });
        // 删除
        var doDelete = function (obj) {
            layer.confirm('确定要删除吗？', function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('api-trade/remittance/deleteRemittance/' + obj.data.id+'/'+obj.data.remittanceId, {}, function (data) {
                    layer.closeAll('loading');
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 500});
                        obj.del();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 500});
                    }
                }, 'DELETE');
            });
        };

        //显示表单弹窗
        var showEditModel = function (data) {
            admin.putTempData('t_remittance', data);
            var title = data ? '修改汇款管理' : '添加';
            admin.popupCenter({
                title: title,
                path: 'pages/trade/remittance_form.html',
                finish: function () {
                    table.reload('remittance-table', {});
                }
            });
        };

        // 搜索按钮点击事件
        $('#remittance-btn-search').click(function () {
            var key = $('#remittance-search-key').val();
            var value = $('#remittance-search-value').val();
            table.reload('remittance-table', {where: {searchKey: key, searchValue: value}});
        });


    });
</script>